|
|
I have a new macro to get a moderately smooth transition between points.
The values will not exceed the range of any interval and it does not
require one to think up two points before and after the range (8-P) as
with a cubic spline. I tried to set it up elegantly with a linear
spline and then #switch case, but I could not get the syntax correct.
Instead, one has to first manually define the points as follows:
--------------------------------------------------------
#declare pn=array[15]
#declare pn[0]=<0.00, -15>;
#declare pn[1]=<0.25, -125>;
#declare pn[2]=<0.35, -117.5>;
#declare pn[3]=<0.45, -110>;
#declare pn[4]=<0.50, -10>;
#declare pn[5]=<0.675, -17.5>;
#declare pn[6]=<0.75, -25>;
#declare pn[7]=<1.00, -15>;
#macro sinespline(n,xgive)
//where n=number of pts-1 (or # in last increment);
// x= given x for which a Y is requested for return.
#declare jj=0;
#while(jj<n)
//#debug str(jj,2,0)
#if(xgive>pn[jj].x &xgive<pn[jj+1].x)
#declare
yreturn=pn[jj].y+(pn[jj+1].y-pn[jj].y)*sin(pi/2*(xgive-pn[jj].x)/(pn[jj+1].x-pn[jj].x));
#else
#debug str(jj,2,0)
#end
#declare jj=jj+1;
#end
#end
-----------------------------------------
If anyone thinks this is of any value to humanity, please make it more
streamlined, if possible.....
Example code demonstrating differences between linear, #init_spline,
and SineSpline:
----------------------------------------------
#version unofficial MegaPov 0.4
#include "colors.inc"
#declare pn=array[15]
#init_spline {"Lshininit",
<0.00, -15>,
<0.25, -125>,
<0.45, -110>,
<0.50, -10>,
<0.75, -25>,
<1.00, -15>
}
#init_spline {"Lshininit2",
<0.00, -15>,
<0.25, -125>,
<0.35, -117.5>,
<0.45, -110>,
<0.50, -10>,
<0.675, -17.5>,
<0.75, -25>,
<1.00, -15>
}
#declare Lshinlinear=spline{
linear_spline
0.00, -15,
0.25, -125,
0.45, -110,
0.50, -10,
0.75, -25,
1.00, -15
}
#declare inputspline=spline{
linear_spline
0.00, -15,
0.25, -125,
0.45, -110,
0.50, -10,
0.75, -25,
1.00, -15
}
#declare pn[0]=<0.00, -15>;
#declare pn[1]=<0.25, -125>;
#declare pn[2]=<0.35, -117.5>;
#declare pn[3]=<0.45, -110>;
#declare pn[4]=<0.50, -10>;
#declare pn[5]=<0.675, -17.5>;
#declare pn[6]=<0.75, -25>;
#declare pn[7]=<1.00, -15>;
#macro sinespline(n,xgive)
#declare jj=0;
#while(jj<n)
//#debug str(jj,2,0)
#if(xgive>pn[jj].x &xgive<pn[jj+1].x)
#declare
yreturn=pn[jj].y+(pn[jj+1].y-pn[jj].y)*sin(pi/2*(xgive-pn[jj].x)/(pn[jj+1].x-pn[jj].x));
#else
#debug str(jj,2,0)
#end
#declare jj=jj+1;
#end
#end
#declare nn=0.001;
#while(nn<1)
sphere {<(nn+0.02)*300,Lshinlinear(nn+0.02).y,0>,3
pigment{Red}
finish{ambient 1}
}
sphere {<nn*300,eval_spline ("Lshininit",nn),3>,3
pigment{Green}
finish{ambient 1}
}
sinespline(7,nn+0.01)
//#declare yg=ygive;
sphere {<(nn+0.01)*300,yreturn,-3>,3
pigment{Blue}
finish{ambient 1}
}
#declare nn=nn+.03;
#end
camera
{
location <130, -75, -300>
look_at <130, -75, 0.0>
}
Post a reply to this message
Attachments:
Download 'sinespline.jpg' (13 KB)
Preview of image 'sinespline.jpg'
|
|